Jump to content

help with INSERT


sportsguy

Recommended Posts

I am trying to update a standings script.  I need to add some MySQL code that adds a division whenever a conference is added.  I need the confname and conforder to be inserted into both sportsdb_conferences and sportsdb_divs tables.

case 'editconferences':
$numconfs = count($_POST['confid']);

for ($i=0;$i<$numconfs;++$i) {
$confname = htmlspecialchars($_POST['confname'][$i], ENT_QUOTES);
$confid = intval($_POST['confid'][$i]);
$conforder = intval($_POST['conforder'][$i]);
$query = "UPDATE ".$db_prefix."sportsdb_conferences SET confname = '$confname', conforder = $conforder WHERE confid = $confid LIMIT 1";
mysql_query($query) or die ("Error in query $query");
print "<p>Conferences updated.</p>";
}

// Add a new conference if there has been a name entered

$confname = htmlspecialchars($_POST['confname'][$i], ENT_QUOTES);
if ($confname <> "") {
$conforder = intval($_POST['conforder'][$i]);
$query = "INSERT INTO ".$db_prefix."sportsdb_conferences (confname,conforder) VALUES ('$confname','$conforder')";
mysql_query($query) or die ("Error in query $query");
print "<p>Conference added as well!</p>";
}

print "<p><a href=\"$update_page\">Back</a></p>";

 

Please help.  Thanks!

Link to comment
Share on other sites

I though I might be getting somewhere with modifying the query as:

	$query = "INSERT INTO ".$db_prefix."sportsdb_conferences (confname,conforder) VALUES ('$confname','$conforder') AND ".$db_prefix."sportsdb_divs (divname,divorder) VALUES ('$divname','$divorder')";

 

No luck!  Help is appreciated.

Link to comment
Share on other sites

I dont think you can do 2 separate queries at the same time. Just split them up into 2.

 

And I dont think <> is a valid checker. do '!=' (not equal to)

 

 

also, add single quotes around the variables(like "where id='$id', not "where id=$id")

 

and also, on your die statement after a query, make it "or die(mysql_error());" that'll help you with what the problem is.

 

And I'm confused with "UPDATE ".$db_prefix."sportsdb_conferences" what is db_prefix? I dont see it declared as anything. I don't think you need multiple different tables for this kind of thing.

Link to comment
Share on other sites

I did not write the script.  It is a stand alone Sports Standings code form http://www.theblog.ca/sports-league-standings.

 

You can ignore the ".$db_prefix." prefix to table name.  That is for my integration into CMS.

 

I contacted the author to inquire removing of the Conference because it is not necessary for my league and confuses the admin process.  At the present time, I have to duplicate the adding of the Division Name as Conference and Division.  I was told,

On the admin side of things, you could add some MySQL code that adds a division whenever a conference is added (under case ‘add’: in the management script). This is quite similar to what you’ve already done, but will help to automate things in the future.

 

On the display side of things, you would just have to treat conferences as divisions. In other words, the index page would still list the conferences, but you would just change it to say that it lists divisions. Then, since each conference of yours contains exactly one division, make the conference view look like a division view (remove the conference title and make the division name print the conference name instead).

Link to comment
Share on other sites

You are missing the point.  I am eliminating a step in the process because it is not necessary.  As previously stated, "I need (help) to add some MySQL code that adds a division whenever a conference is added."  I need to assistance to INSERT data into a second table on submit, inserting into both sportsdb_conferences and sportsdb_divs tables.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.