ludjer Posted August 30, 2006 Share Posted August 30, 2006 i am having problems editing the sql database[code]<?php$hostname_intranet = "localhost";$database_intranet = "intranet";$username_intranet = "root";$password_intranet = "***";$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);$sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID='$clubno'";$sqlview="select * from `intranet`.`club_data` WHERE ClubID='$clubno'"; if(isset($_POST['Submit_1'])) { $gethead = $_POST['head']; $getteacher = $_POST['teacher']; $getnews = $_POST['news']; $getmessage = $_POST['message']; $getmembers = $_POST['members']; $error = ""; if($gethead =="") $error.="*Please enter a head"."<br>"; if($getteacher=="") $error.="*Please enter a Teacher"."<br>"; if($getnews=="") $error.="*Please enter some news"."<br>"; if($getmessage=="") $error.="*Please enter a message"."<br>"; if($getmembers=="") $error.="*Please enter the members of this club"."<br>"; if($error==""){ if(mysql_query($sqlqup)) { echo " Club page updated "; echo '<hr>'; echo 'head:'; echo $gethead; echo '<hr>'; echo 'Teacher:'; echo $getteacher; echo '<hr>'; echo 'News:'; echo $getnews; echo '<hr>'; echo 'Message:'; echo $getmessage; echo '<hr>'; echo 'Members'; echo $getmembers; echo '<hr>'; } else { echo " Failed to upadate"; } } else{ echo "<div align='center'>". $error ."</div>"; } }else { $mclubqu=mysql_query($sqlview); $club= mysql_fetch_array($mclubqu); ?> <div align="center"> <h1><? echo $club['Club']?> Club</h1> <form action="" method="POST"> <table width="588" border="1.2"> <tr> <td width="95">Head</td> <td width="7"> </td> <td width="302"><input name="head" type="text"/></td> <td width="166"><? echo $club['Head']?> </td> </tr> <tr> <td>Teacher</td> <td> </td> <td><input name="teacher" type="text"/></td> <td><? echo $club['Teacher']?> </td> </tr> <tr> <td>News</td> <td> </td> <td><textarea name="news" cols="40" rows="10"></textarea></td> <td><? echo $club['News']?> </td> </tr> <tr> <td>Message</td> <td> </td> <td><textarea name="message" cols="40" rows="10"></textarea></td> <td><? echo $club['Message']?> </td> </tr> <tr> <td>Members</td> <td> </td> <td><textarea name="members" cols="40" rows="10"></textarea></td> <td><? echo $club['members']?> </td> </tr> </tr> <tr> <td> </td> <td> </td> <td><center><input type="submit" name="Submit_1" value="Submit" /> </center> </td> <td> </td> </tr> </table> </form> </div> <?php}?>[/code]my problem is that it says failed to updatethis code here is a magnified verison of the top 1where somthing goes wrong[code]<?php$sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID=$clubno";if(mysql_query($sqlqup)){echo " Club page updated ";echo '<hr>';echo 'head:';echo $gethead;echo '<hr>';echo 'Teacher:';echo $getteacher;echo '<hr>';echo 'News:';echo $getnews;echo '<hr>';echo 'Message:';echo $getmessage;echo '<hr>';echo 'Members';echo $getmembers;echo '<hr>';} else { echo " Failed to upadate"; }[/code]what could be wrong is it a sql query errorcause i have bo clueps it says that the sql query is correct on sqlyogregards ludger Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/ Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 Whats the error, cant help much without seeing the error(s) being returned. Post the errors here Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82766 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 the error is that it does not edit database witch it is ment to edit it just returns to the main page with the header looking like this[code]http://localhost/intranet/clubs/admins/edit.php?head=213324&teacher=234324&latest+news=234324324&message=234234423&members=324324324324&Submit=Submit[/code]PS.. the 1234123 is what i edited it intohere is a better one[code]http://localhost/intranet/clubs/admins/edit.php?head=Ludger&teacher=Piet&latest+news=Welcome&message=This+is+a+club&members=22&Submit=Submit[/code]i am thinking of getting the info from the headder using [code]<?php if (isset($_GET['club'])) $club = $_GET['club'];php?>[/code]but there could be alot of info so i really dont know regardsLudger Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82779 Share on other sites More sharing options...
ober Posted August 30, 2006 Share Posted August 30, 2006 Are you getting the "Failed to Update" error or is the data just not changing?ALWAYS... let me repeat ALWAYS do the following:1) build your query outside of the mysql_query function:<?php$query = "UPDATE tablexyz blah blah";$result = mysql_query($query) or die(mysql_error());?>Right now, you're checking whether you have a valid result or not, but you're not displaying any error or even logging the error. Mysql can provide you with some valuable troubleshooting information! Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82787 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 i have updated it but now there is another error Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82876 Share on other sites More sharing options...
ober Posted August 30, 2006 Share Posted August 30, 2006 .... do you want to tell us what that error was?? Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82881 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 this is what pops up on the screen[quote]Failed to upadate[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82885 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 Chnage this:[code]echo " Failed to upadate";[/code]to[code]echo " Failed to upadate, Reason for failing<br />\n" . mysql_error());[/code]With this code you shoul now get an error message from MySQL why your query is failingWhat I think is the problem is is becuase you are not use quotes around your values. Try thhe following as the query:[code]$sqlqup = "UPDATE club_data SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82888 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 [code]Failed to upadate, Reason for failingYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Teacher=, News=, Message=, members= WHERE ClubID='1'' at line 1[/code]i seei will try it now with quots Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82898 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 From the error you are getting it looks like your variables are being replaced with their values. But I'm not sure. Did the new query work? Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82904 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 ye it did[quote]Club page updated --------------------------------------------------------------------------------head:sanan--------------------------------------------------------------------------------Teacher:none--------------------------------------------------------------------------------News:noen--------------------------------------------------------------------------------Message:13--------------------------------------------------------------------------------Members12213[/quote]but now another errorthey did not go into the databasemy database is emtey[attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82906 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 maby if you could give me a quick example on taking a string and putting it into a database cause i know that it is getting the info from the forms but its not getting onto the databaseit puts " " (nothing and turns current into nothing) in the databasethx alotludger Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82925 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 I think I know whats happing. You are setting up your query before you define the variables you use in your query. The query should be defined before this: [code=php:0]if(mysql_query($sqlqup))[/code] This si what your code should be:[code]<?php$hostname_intranet = "localhost";$database_intranet = "intranet";$username_intranet = "root";$password_intranet = "***";$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);if(isset($_POST['Submit_1'])){ $gethead = $_POST['head']; $getteacher = $_POST['teacher']; $getnews = $_POST['news']; $getmessage = $_POST['message']; $getmembers = $_POST['members']; $error = ""; if($gethead =="") $error.="*Please enter a head"."<br>"; if($getteacher=="") $error.="*Please enter a Teacher"."<br>"; if($getnews=="") $error.="*Please enter some news"."<br>"; if($getmessage=="") $error.="*Please enter a message"."<br>"; if($getmembers=="") $error.="*Please enter the members of this club"."<br>"; if(isset($errro)) { $sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID='$clubno'"; if(mysql_query($sqlqup)) { echo " Club page updated "; echo '<hr>'; echo 'head:'; echo $gethead; echo '<hr>'; echo 'Teacher:'; echo $getteacher; echo '<hr>'; echo 'News:'; echo $getnews; echo '<hr>'; echo 'Message:'; echo $getmessage; echo '<hr>'; echo 'Members'; echo $getmembers; echo '<hr>'; } else { echo " Failed to upadate"; } } else { echo "<div align='center'>". $error ."</div>"; }}else{ $sqlview="select * from `intranet`.`club_data` WHERE ClubID='$clubno'"; $mclubqu = mysql_query($sqlview); $club = mysql_fetch_array($mclubqu);?> <div align="center"> <h1><? echo $club['Club']?> Club</h1> <form action="" method="POST"> <table width="588" border="1.2"> <tr> <td width="95">Head</td> <td width="7"> </td> <td width="302"><input name="head" type="text"/></td> <td width="166"><? echo $club['Head']?> </td> </tr> <tr> <td>Teacher</td> <td> </td> <td><input name="teacher" type="text"/></td> <td><? echo $club['Teacher']?> </td> </tr> <tr> <td>News</td> <td> </td> <td><textarea name="news" cols="40" rows="10"></textarea></td> <td><? echo $club['News']?> </td> </tr> <tr> <td>Message</td> <td> </td> <td><textarea name="message" cols="40" rows="10"></textarea></td> <td><? echo $club['Message']?> </td> </tr> <tr> <td>Members</td> <td> </td> <td><textarea name="members" cols="40" rows="10"></textarea></td> <td><? echo $club['members']?> </td> </tr> </tr> <tr> <td> </td> <td> </td> <td><center><input type="submit" name="Submit_1" value="Submit" /> </center> </td> <td> </td> </tr> </table> </form> </div> <?php}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82930 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 it says no database selected??[code]Failed to upadate, Reason for failingNo database selected[/code]i used your code and it said thatthen i tried using my code but just move$sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID='$clubno'"; if(mysql_query($sqlqup))same resault both ways Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82967 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 Add[code]mysql_select_db($database_intranet, $intranet);[/code]after[code]$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82969 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 Failed to upadate, Reason for failingYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''club_data' SET Head=sanan, Teacher=none, News=noneeen, Message=noneoneo, member' at line 1here is my qeury[code]UPDATE 'club_data' SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82974 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 You dont need quotes around club_data, that is fine on its own as its the table name. You only use quotes around the columns values.So use this as the query:[code]UPDATE club_data SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'[/code]If I put quotes around club_data then I apologiese fro my mistake. Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82976 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 if there are no quots then it gives no database selectedso i used your query and add the quots and this is what i gotwith quots:[code]Failed to upadate, Reason for failingYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''club_data' SET Head='sanan', Teacher='none', News='noneeen', Message='noneoneo'' at line 1[/code]without:[code]Failed to upadate, Reason for failingNo database selected[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82977 Share on other sites More sharing options...
.josh Posted August 30, 2006 Share Posted August 30, 2006 please re-post all of your code as it looks like now. Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82980 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 [code]<?php/*session checker */if (!isset($_SESSION)) { session_start();}$MM_authorizedUsers = "";$MM_donotCheckaccess = "true";// *** Restrict Access To Page: Grant or deny access to this pagefunction isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { // For security, start by assuming the visitor is NOT authorized. $isValid = False; // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. // Therefore, we know that a user is NOT logged in if that Session variable is blank. if (!empty($UserName)) { // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. // Parse the strings into arrays. $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } // Or, you may restrict access to only certain users based on their username. if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && true) { $isValid = true; } } return $isValid; }$MM_restrictGoTo = "login.php";if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) $MM_referrer .= "?" . $QUERY_STRING; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit;}##club veryfiyerif (isset($_GET['club'])) $club = $_GET['club']; else $club = 'error';$error='no';switch ($club) {case 'error': $error='yes'; break;case '1': $clubno='1'; break;case '2': $clubno='2'; break;case '3': $clubno='3'; break;default:$error='yes';break;} $hostname_intranet = "localhost";$database_intranet = "intranet";$username_intranet = "root";$password_intranet = "jam3s0n";$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);mysql_select_db($club_data, $intranet);if(isset($_POST['Submit_1'])){ $gethead = $_POST['head']; $getteacher = $_POST['teacher']; $getnews = $_POST['news']; $getmessage = $_POST['message']; $getmembers = $_POST['members']; $error = ""; if($gethead =="") $error.="*Please enter a head"."<br>"; if($getteacher=="") $error.="*Please enter a Teacher"."<br>"; if($getnews=="") $error.="*Please enter some news"."<br>"; if($getmessage=="") $error.="*Please enter a message"."<br>"; if($getmembers=="") $error.="*Please enter the members of this club"."<br>"; if(isset($error)) { $sqlqup= "UPDATE 'club_data' SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'"; if(mysql_query($sqlqup)) { echo " Club page updated "; echo '<hr>'; echo 'head:'; echo $gethead; echo '<hr>'; echo 'Teacher:'; echo $getteacher; echo '<hr>'; echo 'News:'; echo $getnews; echo '<hr>'; echo 'Message:'; echo $getmessage; echo '<hr>'; echo 'Members'; echo $getmembers; echo '<hr>'; } else { echo " Failed to upadate, Reason for failing<br />\n" . mysql_error(); } } else { echo "<div align='center'>". $error ."</div>"; }}else{ $sqlview="select * from `intranet`.`club_data` WHERE ClubID='$clubno'"; $mclubqu = mysql_query($sqlview); $club = mysql_fetch_array($mclubqu);?> <div align="center"> <h1><? echo $club['Club']?> Club</h1> <form action="" method="POST"> <table width="588" border="1.2"> <tr> <td width="95">Head</td> <td width="7"> </td> <td width="302"><input name="head" type="text"/></td> <td width="166"><? echo $club['Head']?> </td> </tr> <tr> <td>Teacher</td> <td> </td> <td><input name="teacher" type="text"/></td> <td><? echo $club['Teacher']?> </td> </tr> <tr> <td>News</td> <td> </td> <td><textarea name="news" cols="40" rows="10"></textarea></td> <td><? echo $club['News']?> </td> </tr> <tr> <td>Message</td> <td> </td> <td><textarea name="message" cols="40" rows="10"></textarea></td> <td><? echo $club['Message']?> </td> </tr> <tr> <td>Members</td> <td> </td> <td><textarea name="members" cols="40" rows="10"></textarea></td> <td><? echo $club['members']?> </td> </tr> </tr> <tr> <td> </td> <td> </td> <td><center><input type="submit" name="Submit_1" value="Submit" /> </center> </td> <td> </td> </tr> </table> </form> </div> <?php}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82981 Share on other sites More sharing options...
.josh Posted August 30, 2006 Share Posted August 30, 2006 [code]$sqlqup= "UPDATE club_data SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'";[/code]that's how it should look. as wildteen said, no quotes around the table name. but you say it gives you a no database selected error when you do this? edit: shouldn't mysql_select_db($club_data, $intranet);be mysql_select_db($database_intranet, $intranet); Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82985 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 yip it says Failed to upadate, Reason for failingNo database selectedand if i do put quots around it thenFailed to upadate, Reason for failingYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''club_data' SET Head='sanan', Teacher='none', News='noneeen', Message='noneoneo'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82991 Share on other sites More sharing options...
.josh Posted August 30, 2006 Share Posted August 30, 2006 shouldn'tmysql_select_db($club_data, $intranet);bemysql_select_db($database_intranet, $intranet); Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82993 Share on other sites More sharing options...
ludjer Posted August 30, 2006 Author Share Posted August 30, 2006 IT works !! ;D ;D ;D ;Dthx alot every1 that helpedwildteen88Crayon Violentit was this[quote]shouldn'tmysql_select_db($club_data, $intranet);bemysql_select_db($database_intranet, $intranet);[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/19134-x-solved-xerror-editing-mysql-using-php/#findComment-82996 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.