Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/MySQL problems

Status
Not open for further replies.

frozenpeas

Technical User
Sep 13, 2001
893
CA
Everything worked fine - then I had to redo my server.

The problem:

I add data to my db through a form in a php page. It seems to add it fine. When I look at the db, the new entries are empty.

I have another form where I retrieve db entries so I can edit them. When I try to do this now, I get:

Code:
Could not query database. You have an error in your SQL syntax near '' at line 1

The first few lines in question being:

Code:
<?
require_once('connect.php');
require_once('output_fns.php');
html_header(':: Edit Service Record');
?>
<form action=&quot;edit_record.php&quot; method=&quot;post&quot; name=&quot;form&quot; id=&quot;form&quot;>
          <?
		  $record = $radiobutton;
		  $datetoday = date('m/d/y');
		  $query = mysql_query('SELECT * FROM cecil_service WHERE id = '.$record) or die ('Could not query database. '.mysql_error());
		  $row = mysql_fetch_array($query);
		  ?>

I hope that's enough info. Thanks. frozenpeas
 
Have you tried

$query = mysql_query(&quot;SELECT * FROM cecil_service WHERE id='$record'&quot;) or die blah blah blah

?

Quite often you need single quotes around the WHERE match.

And I agree with the above poster, I'd throw in a

echo &quot;$record&quot;;
Just above your call to make sure it has what you think it does.

-Rob
 
Befor you submit the query..just echo it using
echo($query); and you will be clear where the mistake is
 
Like I said, everything worked fine before I redid my server.

$record contains what it should, the query worked fine, etc.
frozenpeas
 
i agree with skiflyer, i think its a problem with not having quotes around $record var. i would imagine by redoing your server a php.ini setting like magic quotes or something got switched on you. dont quote me on this but perhaps if you have access to change the values you could fix all your problems instead of rewriting a bunch of code. there are also ini_set() functions believe you could look into as well. for the time being though try entering your query as such:

$query = mysql_query(&quot;SELECT * FROM cecil_service WHERE id = \&quot;&quot;.$record.&quot;\&quot;&quot;) or die (&quot;Could not query database&quot;.mysql_error());

this is the format i use for all my queries. supposedly you can use single quotes inside double quotes instead of escaping them as i do but i havent gotten that to work. hopefully this will help you out though :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top